<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Users</title>
    <meta name="layout" content="main" />
    <g:javascript>
        $(document).ready(function(){

        });
    </g:javascript>
</head>
<body>

<div>
    <h1>Users</h1>
    <hr/>
    <br/>
    <div class="css_right toolbar">
        <sec:ifAllGranted roles="ROLE_ADMIN">
            <a id="newScriptButton" class="btn-text" href="${createLink(controller: 'account', action: 'create')}">Create User</a>
        </sec:ifAllGranted>
    </div>
    <br/>
    <br/>
    <br/>
    <table>
        <tr>
            <th>User Name</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Created</th>
            <th>Enabled</th>
            <th></th>
        </tr>
        <g:each in="${accounts}" status="accountIndex" var="account">
            <tr class="${accountIndex%2 ? 'odd' : 'even'}">
                <td>
                    <g:link controller="account" action="view" id="${account.userId}">${account.username}</g:link>
                </td>
                <td >${account.firstName}</td>
                <td >${account.lastName}</td>
                <td title="${account.dateCreated}"><prettytime:display date="${account.dateCreated}" /></td>
                <td >${account.enabled}</td>
                <td>
                    <div class="toolbar">
                        <sec:ifAllGranted roles="ROLE_ADMIN">
                            <g:unless test="${account.username.equals('admin')}">
                                <g:if test="${account.enabled}">
                                    <a class="btn-text" href="${createLink(controller: 'account', action: 'disable', id: account.userId, params: [origin: request.forwardURI.toString().decodeURL()])}">Disable</a>
                                </g:if>
                                <g:else>
                                    <a class="btn-text" href="${createLink(controller: 'account', action: 'enable', id: account.userId, params: [origin: request.forwardURI.toString().decodeURL()])}">Enable</a>
                                </g:else>
                                <a class="btn-text" href="${createLink(controller: 'account', action: 'delete', id: account.userId)}" onclick="return confirm('Are you sure?');">Delete</a>
                            </g:unless>
                        </sec:ifAllGranted>
                    </div>
                </td>
            </tr>
        </g:each>
    </table>
</div>

</body>
</html>